package com.os.opencv.java.chapter4;

import org.opencv.core.*;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class BitwiseAnd {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        //读取图像文件并在屏幕上显示
        Mat src = Imgcodecs.imread("/Users/matt/MATT-MAC/matt_workspace/OS-OpenCV_workspace/test.jpg",
                Imgcodecs.IMREAD_GRAYSCALE);
        HighGui.imshow("src", src);
        HighGui.waitKey(0);

        //创建一个窗口图像，北京维全黑色，中央区域有一个白色实心矩形
        Scalar white = new Scalar(255, 255, 255);
        Mat window = Mat.zeros(src.size(), CvType.CV_8UC1);
        Imgproc.rectangle(window, new Point(400, 40), new Point(660, 250), white, -1);

        //在屏幕上显示窗口图像
        HighGui.imshow("window", window);
        HighGui.waitKey(0);

        //进行按位与操作
        Mat dst = new Mat();
        Core.bitwise_and(src, window, dst);

        //在屏幕上显示结果
        HighGui.imshow("dst", dst);
        HighGui.waitKey(0);

        System.exit(0);
    }
}
